package com.dao.imp;

import com.dao.CompanyDao;
import com.entity.Job;
import com.utils.DButil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class CompanyDaoimpl implements CompanyDao {

    @Override
    public int AddJob(Job job) {
        Connection conn = DButil.getConn();
        String sql="insert  into r_job(companyid,jobname,jobdescription,jobtype,salary,jobaddress,jobstate,audit_opinion,low,high) values(?,?,?,?,?,?,?,?,?,?) ";
        try {
            PreparedStatement ps= conn.prepareStatement(sql);
            ps.setString(1,job.getCompanyId());
            ps.setString(2,job.getJobName());
            ps.setString(3,job.getJobDescription());
            ps.setString(4,job.getJobType());
            ps.setString(5,job.getSalary());
            ps.setString(6,job.getCompanyAddress());
            ps.setString(7,job.getState());
            ps.setString(8,job.getAudit_opinion());
            ps.setString(9, String.valueOf(job.getLow()));
            ps.setString(10, String.valueOf(job.getHigh()));
            int i = ps.executeUpdate();
            if (i==1){
                    return  1;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int delJob(String jobId) {
        Connection conn = DButil.getConn();
        String sql="DELETE from r_job where jobid=?";
        try {
            PreparedStatement ps= conn.prepareStatement(sql);
            ps.setInt(1, Integer.parseInt(jobId));
            int i = ps.executeUpdate();
            if (i==1){
                return  1;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

}
